<?php
	include("includes/connect.php");
	//include("includes/function.php");


	$ppID = $_REQUEST["ppID"];
	$db = new myDBS;

	$where = "petition_id = '$petition_id'";
	$result = $db->showData1("tbl_petition", $where);

	$rows = $db->fetch_object ( $result );

?>

<script type="text/javascript">
	$(document).ready(function(){

		//$.post('dropdown.php', {  tablename: 'tbl_creditor', dd: 'dd_payfor', idname: 'name' , fieldname: 'name' }, function(data) { $("#payfor").html(data); } );
		$.post('dropdown.php', {  tablename: 'expend', dd: 'dd_expend_type', idname: 'expend_id', fieldname: 'expend_type' }, function(data) { $("#expend_type").html(data); } );

		//$.post('genKeytemp.php', function(data) { $("#key").html(data); } );

		$.fn.myFunction = function() { 
			var inpValues = $("#inpValues").val();
			var WithholdingTax = $("#WithholdingTax").val();
			var inpPenalty = $("#inpPenalty").val();

			inpValues= parseFloat(inpValues);
			WithholdingTax= parseFloat(WithholdingTax);

			WithholdingTax= inpValues * WithholdingTax / 100;
			$("#sHoldingTax").html(WithholdingTax);

			inpNet = inpValues - WithholdingTax - inpPenalty;
			$("#inpNet").val(inpNet);
		 }

		$("input,select,textarea").not("[type=submit]").jqBootstrapValidation({
			submitSuccess: function ($form, event) { 
				event.preventDefault();
				//var ppID = $(#ppID)

				$.ajax({
					type: "POST",
					url: "processPetition.php",
					data: $('#frmPetition').serialize(),
					cach: false,
					error: function() {
						alert("ERROR !!!!");
					},
					success: function(data){
						//alert(data);
						//window.location.href="index.php";
						//$('#myTab a[href="#profile"]').tab('show');
						//$("#kob").after(data);
						//$("#dispStatus").html(data);
						window.location.href="index.php?pages=sumPetition&petition_id=" + data;

					}
				});

			}
		});

		$( "#treasury_date" ).datepicker({
			showButtonPanel: true
		 });
		
		$("#add_payfor").click(function() {
			//event.preventDefault();
			//alert("asdfas");
			var dd_payfor = $("#dd_payfor").val();
			var xxx_id = $("#h_key").val();
			var inpAmount = $("#inpAmount").val();
			var task = "insert";

			$.ajax({
				type: "POST",
				url: "payfor.php",
				data: { 'task': task, 'payfor': dd_payfor, 'inpAmount': inpAmount, 'xxx_id': xxx_id },
				cach: false,
				error: function() {
					alert("ERROR !!!!");
				},
				success: function(data){
					if(data) { $("#kob").html(data); }
				}
			});
			
		});

		$("#inpTax").keyup(function() {
			var inpValues = $("#inpValues").val();
			var inpTax = $("#inpTax").val();

			inpValues= parseFloat(inpValues);

			inpTax= parseFloat(inpTax);

			inpTax = inpValues - ((inpValues * 100) / (100+ inpTax));

			$("#stax").html(inpTax);

		});

		$("#inpTax").change(function() {
			var inpValues = $("#inpValues").val();
			var inpTax = $("#inpTax").val();

			inpValues= parseFloat(inpValues);

			inpTax= parseFloat(inpTax);

			inpTax = inpValues - ((inpValues * 100) / (100+ inpTax));

			$("#stax").html(inpTax);

		});

		$("#WithholdingTax").keyup(function() {
			$.fn.myFunction();

		});

		$("#WithholdingTax").change(function() {
			$.fn.myFunction();
		});

		$("#inpPenalty").keyup(function() {
			$.fn.myFunction();

		});
		
		$("#inpPenalty").change(function() {
			$.fn.myFunction();

		});

		$("#inpValues").keyup(function() {
			/*
			//alert(event.which);
			if((event.which >= 48 && event.which <= 57) || (event.which >= 96 && event.which <= 105) || event.which == 110 || (event.which >= 37 && event.which <= 40) || event.which==8 || event.which==46) {
				//alert("asdf");
			}
/*
			} else {
				event.preventDefault();
			}
*/
		});
		
	}); //(document).ready

	function del_temp(id){
		var task = "delete";
		//alert(id);
		if (confirm('คุณแน่ใจที่จะลบรายการนี้หรือไม่? ')) {
			$.post('payfor.php',{task: task, id: id}, function(data) {
					$("#kob").html(data);
			});
		}
	}
	

</script>

<div id="dispStatus"></div>
<form id="frmPetition" name="frmPetition" method="post" action="#" novalidate="">
    <div class="row-fluid">
        <div class="control-group span7">
            <label class="control-label">ส่วนราชการ</label>
            <div class="controls">
				<!--<span class="span7 uneditable-input">เทศบาลอุดรธานี</span>-->
                <input class="span7 uneditable-input" type="text" id="gov" name="gov" value="<?php echo $rows->gov; ?>" readonly />
            </div>                
        </div>
		<div class="control-group span5">
            <label class="control-label">หน่วย</label>
            <div class="controls">
				<input class="span5 uneditable-input" type="text" id="gang" name="gang" value="<?php echo $rows->gang; ?>" readonly />
            </div>                
        </div>
    </div>

    <div class="row-fluid">
         <div class="control-group span2">
            <label class="control-label">ปีงบประมาณ</label>
            <div class="controls">
				<input class="span2 uneditable-input" type="text" id="dd_budget_year" name="dd_budget_year" value="<?php echo $rows->dd_budget_year; ?>" readonly />
            </div>                
        </div>
        <div class="control-group span3">
            <label for="dob" class="control-label">เลขที่ผู้เบิก</label>
            <div class="controls">
                <input class="span12" type="text" id="p_id" name="p_id" value="" readonly />
            </div>
        </div>
		<div class="control-group span3">
            <label for="dob" class="control-label">เลขที่คลังรับ</label>
            <div class="controls">
				<input class="span12" type="text" id="treasury_id" name="treasury_id" value="" readonly />
             </div>
        </div>
		<div class="control-group  span3">
            <label for="dob" class="control-label">วันที่คลังรับ</label>
            <div class="controls">
                <input class="span12" type="text" id="treasury_date" name="treasury_date" readonly/>
			</div>
        </div>
    </div>
	
	<div class="row-fluid">
        <div class="control-group span4">
            <label class="control-label">แผนงาน</label>
            <div class="controls">
				<input class="span12" type="text" id="panngan2_name" name="panngan2_name" value="<?php echo $rows->panngan2_name;?>" readonly />
            </div>                
        </div>	
		<div class="control-group span4">
            <label class="control-label">งาน</label>
            <div class="controls">
				<input class="span12" type="text" id="panngan3_name" name="panngan3_name" value="<?php echo $rows->panngan3_name;?>" readonly />
            </div>                
        </div>
		<div class="control-group span2">
            <label class="control-label">รหัสบัญชี</label>
            <div class="controls">
				<input class="span12" type="text" id="acc_id" name="acc_id" value="<?php echo $rows->acc_id;?>"  />
            </div>                
        </div>
		<div class="control-group span2">
            <label class="control-label">E-lass</label>
            <div class="controls">
				<input class="span12" type="text" id="elass" name="elass" value="<?php echo $rows->elass;?>"  />
            </div>                
        </div>
    </div>

	<div class="row-fluid">
        <div class="control-group span4">
            <label class="control-label">หมวด / ลักษณะ</label>
            <div id="expend_type" class="controls">
				<select class="span12" id="dd_expend_type" name="dd_expend_type" >
					<option><?php echo $rows->dd_expend_type;?></option>
				</select>
            </div>                
        </div>
		<div class="control-group span4">
            <label class="control-label">ประเภท</label>
            <div id="expend_sub_type" class="controls">
				<select class="span12" id="dd_expend_sub_type" name="dd_expend_sub_type">
					<option><?php echo $rows->dd_expend_sub_type;?></option>
				 </select>
            </div>                
        </div>
		<div class="control-group span4">
            <label class="control-label">รายการ</label>
            <div id="expend_mini_type" class="controls">
				<select class="span12"  id="dd_expend_mini_type" name="dd_expend_mini_type">
				  <option>เลือก...</option>
				 </select>
            </div>                
        </div>
    </div>
<div class="row-fluid">

		<div class="form-horizontal span5">
			<div class="control-group">
			<label class="control-label" for="inpValues">มูลค่าสินค้า / บริการ</label>
			<div class="controls">
			  <input type="number" id="inpValues" name="inpValues" placeholder="มูลค่าสินค้า / บริการ" value="<?php echo $rows->inpValues; ?>"  readonly>
			</div>
		  </div>
		  <div class="control-group">
			<label class="control-label" for="inpTax">บวก ภาษีมูลค่าเพิ่ม (%)</label>
			<div class="controls">
			  <input class="span2" type="number" id="inpTax" name="inpTax" placeholder="ภาษีมูลค่าเพิ่ม" value="<?php echo $rows->inpTax; ?>" ><span id="stax" class="span2 uneditable-input"></span>
			</div>
		  </div>
		  <div class="control-group">
			<label class="control-label" for="inpTotal">จำนวนเงินที่ขอเบิกทั้งสิ้น</label>
			<div class="controls">
			  <input type="text" id="inpTotal" name="inpTotal" placeholder="จำนวนเงินที่ขอเบิกทั้งสิ้น" value="<?php echo $rows->inpTotal; ?>" readonly>
			</div>
		  </div>
		  <div class="control-group">
			<label class="control-label" for="WithholdingTax">หัก ภาษี ณ ที่จ่าย</label>
			<div class="controls">
			  <input class="span2" type="number" id="WithholdingTax" name="WithholdingTax" placeholder="ภาษี ณ ที่จ่าย" value="<?php echo $rows->WithholdingTax; ?>" ><span id="sHoldingTax" class="span2 uneditable-input"></span>
			</div>
		  </div>
		  <div class="control-group">
			<label class="control-label" for="inpPenalty">ค่าปรับ</label>
			<div class="controls">
			  <input type="number" id="inpPenalty" name="inpPenalty" placeholder="ค่าปรับ" value="<?php echo $rows->inpPenalty; ?>">
			</div>
		  </div>
		  <div class="control-group">
			<label class="control-label" for="inpNet">จำนวนเงินที่่รับสุทธิ</label>
			<div class="controls">
			  <input type="text" id="inpNet" name="inpNet" placeholder="จำนวนเงินที่่รับสุทธิ" value="<?php echo $rows->inpNet; ?>" readonly>
			</div>
		  </div>
		</div> <!-- <div class="form-horizontal span5"> -->

	
		<div class="span7">
			<div class="row-fluid">
			<div id="kob">
				<table class="table table-bordered" width="100%">
					<thead>
						<tr bgcolor="#e5e5e5">
						<th>ชื่อ - นามสกุล / บริษัท</th>
						
						</tr>
					</thead>
					<tbody>
						<tr>
							<td><?php echo $rows->company_name; ?>&nbsp;</td>
						</tr>
						<tr>
							<td>&nbsp;</td>
						</tr>
					</tbody>
				</table>
			</div>
		</div>

		</div><!-- <div class="span8"> -->

</div>
	
	<input type="hidden" id="company_name" name="company_name" value="<?php echo $rows->company_name; ?>">
	<input type="hidden" id="ppID" name="ppID" value="<?php echo $ppID; ?>">
	<input type="hidden" id="task" name="task" value="edit">
	<input type="hidden" id="petition_id" name="petition_id" value="<?php echo $petition_id; ?>">
	<div id="key">
		<input type="hidden" id="h_key" name="h_key" value="">
	</div>
	<p class="pull-right">

	<button type="submit" id="submit" class="btn btn-primary"><i class="icon-ok icon-white"></i> บันทึกข้อมูล</button>
	<a href="index.php?pages=home" role="button" class="btn"><i class="icon-remove"></i>ยกเลิก</a>
	</p>

</form> 